//
//  Consume_GoodsDetailViewController.m
//  JinFuThree
//
//  Created by 爱尚 on 2018/9/4.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "Consume_GoodsDetailViewController.h"
#import "Consume_GD_TopTableViewCell.h"
#import "Consume_GD_AddressTableViewCell.h"
#import "Consume_GD_MonthPayView.h"
#import "Consume_SelectInstalmentView.h"

@interface Consume_GoodsDetailViewController ()<UITableViewDelegate,UITableViewDataSource,Consume_SelectInstalmentViewDelegate>
@property(nonatomic,strong)UITableView *myTabelView;
@property(nonatomic,strong)Consume_GD_MonthPayView *payView;
@property(nonatomic,strong)NSArray *selectArr;



@end

@implementation Consume_GoodsDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"商品详情";
    [self initViews];
}

-(void)initViews{


    [self.view addSubview:self.payView];
    [self.payView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(self.view);
        make.height.mas_offset(@50);
    }];
    self.myTabelView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.myTabelView.dataSource = self;
    self.myTabelView.delegate = self;
    [self.myTabelView registerClass:[Consume_GD_TopTableViewCell class] forCellReuseIdentifier:@"Consume_GD_TopTableViewCell"];
    [self.myTabelView registerClass:[Consume_GD_AddressTableViewCell class] forCellReuseIdentifier:@"Consume_GD_AddressTableViewCell"];
    self.myTabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.myTabelView];
    [self.myTabelView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(self.view);
    }];
    self.myTabelView.contentInset = UIEdgeInsetsMake(0, 0, 50, 0);
    [self.myTabelView reloadData];
    
    [self.view bringSubviewToFront:self.payView];
    
}

#pragma mark ----------tableViewDelegate---------------------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        Consume_GD_TopTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Consume_GD_TopTableViewCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        Consume_GD_AddressTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Consume_GD_AddressTableViewCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    
    
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return ScreenWidthMao+125;
    }else{
        return 100;
    }
    
}
-(void)topBtnAction{
    
    [UIView animateWithDuration:0.0 animations:^{
        Consume_SelectInstalmentView *view = [[Consume_SelectInstalmentView alloc]init];
        view.selectInstalmentViewDelegate = self;
        [view show:@[@"1期",@"3期",@"6期",@"12期",@"24期"]];
        self.selectArr = view.InstallmentArray;
    }];
    
}
-(void)sureBtnAction:(UIButton *)sender{
    UIButton *btn = self.selectArr[sender.tag -100];
    NSString *str =btn.titleLabel.text;
    
    self.payView.instalmentLabel.text = [NSString stringWithFormat:@"分期期数是%@",str];
    
}

-(Consume_GD_MonthPayView *)payView{
    if (!_payView) {
        _payView = [[Consume_GD_MonthPayView alloc]initWithFrame:CGRectZero];
        _payView.backgroundColor = [UIColor whiteColor];
        [_payView.topBtn addTarget:self action:@selector(topBtnAction) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _payView;
}
-(NSArray *)selectArr{
    if (!_selectArr) {
        _selectArr = [[NSArray alloc]init];
    }
    return _selectArr;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
